package com.ruoyi.swla2.service.impl;

import java.util.List;
import java.util.Map;

import cn.hutool.core.collection.CollUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.swla2.mapper.GisPointMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.swla2.mapper.GisLineMapper;
import com.ruoyi.swla2.domain.GisLine;
import com.ruoyi.swla2.service.IGisLineService;

/**
 * GIS管网-管线Service业务层处理
 *
 * @author gdqt
 * @date 2023-11-26
 */
@Service
public class GisLineServiceImpl implements IGisLineService {
    @Autowired
    private GisLineMapper gisLineMapper;

    /**
     * 查询GIS管网-管线
     *
     * @param id GIS管网-管线主键
     * @return GIS管网-管线
     */
    @Override
    public GisLine selectGisLineById(Long id) {
        return gisLineMapper.selectGisLineById(id);
    }

    /**
     * 查询GIS管网-管线列表
     *
     * @param gisLine GIS管网-管线
     * @return GIS管网-管线
     */
    @Override
    public List<GisLine> selectGisLineList(GisLine gisLine) {
        return gisLineMapper.selectGisLineList(gisLine);
    }

    /**
     * 新增GIS管网-管线
     *
     * @param gisLine GIS管网-管线
     * @return 结果
     */
    @Override
    public int insertGisLine(GisLine gisLine) {
        gisLine.setCreateTime(DateUtils.getNowDate());
        return gisLineMapper.insertGisLine(gisLine);
    }

    /**
     * 修改GIS管网-管线
     *
     * @param gisLine GIS管网-管线
     * @return 结果
     */
    @Override
    public int updateGisLine(GisLine gisLine) {
        gisLine.setUpdateTime(DateUtils.getNowDate());
        return gisLineMapper.updateGisLine(gisLine);
    }

    /**
     * 批量删除GIS管网-管线
     *
     * @param ids 需要删除的GIS管网-管线主键
     * @return 结果
     */
    @Override
    public int deleteGisLineByIds(Long[] ids) {
        return gisLineMapper.deleteGisLineByIds(ids);
    }

    /**
     * 删除GIS管网-管线信息
     *
     * @param id GIS管网-管线主键
     * @return 结果
     */
    @Override
    public int deleteGisLineById(Long id) {
        return gisLineMapper.deleteGisLineById(id);
    }

    @Override
    public void updateGisLinePointsXY(String expNo, String oldPointStr, String newPointStr) {
        List<GisLine> gisLineList = gisLineMapper.selectGisLineByExpNo(expNo);
        if (CollUtil.isNotEmpty(gisLineList)) {
            gisLineList.forEach(line -> {
                System.out.println("expNo==" + expNo);
                System.out.println("oldPointStr==" + oldPointStr);
                System.out.println("newPointStr==" + newPointStr);
                line.setGeom(line.getGeom().replace(oldPointStr, newPointStr));
                gisLineMapper.updateGisLine(line);
            });
        }
    }

    @Override
    public void updateGisLinePointsDeep(String expNo, Double newDeep) {
        List<GisLine> gisLineList = gisLineMapper.selectGisLineByExpNo(expNo);
        if (CollUtil.isNotEmpty(gisLineList)) {
            gisLineList.forEach(line -> {
                if (line.getsPoint().equals(expNo)) {
                    line.setsDeep(newDeep);
                }
                if (line.getePoint().equals(expNo)) {
                    line.seteDeep(newDeep);
                }
                gisLineMapper.updateGisLine(line);
            });
        }
    }

    @Override
    public List<GisLine> getPipeLengthData(Map<String, Object> queryMap) {
        return gisLineMapper.getPipeLengthData(queryMap);
    }

    @Override
    public List<GisLine> getLineAlarmData(Map<String, Object> queryMap) {
        return gisLineMapper.getLineAlarmData(queryMap);
    }
}
